import java.util.Scanner;

public class Test6 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int v = in.nextInt();
            in.nextLine();
            int len = in.nextInt();
            in.nextLine();
            int[] volum = new int[len];
            for (int i = 0; i < len; i++) {
                volum[i] = in.nextInt();
                in.nextLine();
            }
            int[][] dp = new int[len+1][v+1];
            for (int i = 1; i <= len; i++) {
                for (int j = 0; j <= v; j++) {
                    dp[i][j] = dp[i-1][j];
                    if (j >= volum[i-1]) {
                        dp[i][j] = Math.max(dp[i][j], dp[i-1][j-volum[i-1]] + volum[i-1]);
                    }
                }
            }
            System.out.println(v-dp[len][v]);
        }
    }

    public static void main1(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int v = in.nextInt();
            in.nextLine();
            int len = in.nextInt();
            in.nextLine();
            int[] volum = new int[len];
            for (int i = 0; i < len; i++) {
                volum[i] = in.nextInt();
                in.nextLine();
            }
            int[] dp = new int[v+1];
            for (int i = 1; i <= len; i++) {
                for (int j = v; j >= volum[i-1]; j--) {
                    dp[j] = Math.max(dp[j], dp[j-volum[i-1]] + volum[i-1]);
                }
            }
            System.out.println(v-dp[v]);
        }
    }
}
